<template>
	<div class="dashboard-container">
		<div @click="$router.go(-1)">
			<i class="el-icon-back"></i>
			<span>返回</span>
		</div>
		<el-card style="margin-bottom: 20px">
			<!-- 给el-form绑定form -->
			<el-form label-width="" :model="form" :inline="true">
				<el-form-item label="店员or老板id">
					<el-input v-model="form.shanghuuserid" placeholder="" clearable />
				</el-form-item>
				<el-form-item label="商户id">
					<el-input v-model="form.shanghuid" placeholder="" clearable />
				</el-form-item>
				<el-form-item label="店员or老板昵称">
					<el-input v-model="form.nickname" placeholder="" clearable />
				</el-form-item>
				<el-form-item label="商户昵称">
					<el-input v-model="form.name" placeholder="" clearable />
				</el-form-item>
				<el-form-item label="店员or老板手机号">
					<el-input v-model="form.phone" placeholder="" clearable />
				</el-form-item>
				<el-form-item label="日期">
					<el-date-picker @change="dateChange" value-format="timestamp" v-model="dateRange" type="daterange"
						placeholder="请选择" size="default" />
				</el-form-item>
				<el-button type="primary" icon="el-icon-search" @click="searchclick"
					style="margin-left: 12px">筛选</el-button>
				<el-button @click="resetSearch">重置</el-button>
				<el-button type="primary" icon="el-icon-download" @click="exportData"
					style="margin-left: 12px">导出</el-button>
			</el-form>
		</el-card>
		<el-table :data="tableData" border>
			<el-table-column prop="id" label="ID" align="center"> </el-table-column>
			<el-table-column prop="nickname" label="昵称" align="center">
			</el-table-column>
			<el-table-column prop="phone" label="手机号" align="center">
			</el-table-column>
			<el-table-column prop="title" label="操作记录" align="center">
			</el-table-column>
			<el-table-column prop="dayint" label="时间" align="center">
				<template slot-scope="scope">
					{{ scope.row.dayint | datefilter }}
				</template>
			</el-table-column>

		</el-table>
		<Pagination :currentPage="this.form.pageNo" :size="this.form.pageSize" :total="total" @changelimit="changelimit"
			@changecurrentPage="changecurrentPage"></Pagination>
	</div>
</template>

<script>
	import {
		logListApi
	} from "@/api/userlog";
	export default {
		name: "Dashboard",
		data() {
			return {
				dateRange: [],
				form: {
					pageNo: 1,
					pageSize: 15,
					shanghuuserid: '',
					shanghuid: '',
					nickname: '',
					name: '',
					phone: '',
					inttime: '',
					endtime: '',
				},
				total: 0,
				tableData: [],
			};
		},
		filters: {
			datefilter(val) {
				if (val) {
					var date = new Date(parseInt(val) * 1000);
					var Year = date.getFullYear();
					var Moth =
						date.getMonth() + 1 < 10 ?
						"0" + (date.getMonth() + 1) :
						date.getMonth() + 1;
					var Day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
					var Hour =
						date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
					var Minute =
						date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
					var Sechond =
						date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
					var GMT = Year + "-" + Moth + "-" + Day +
						"   " +
						Hour +
						":" +
						Minute +
						":" +
						Sechond;

					return GMT;
				} else {
					return "";
				}
			},
		},
		methods: {
			exportData() {
				let param = {
					inttime: this.form.inttime == "" ?
						"" : Math.floor(new Date(this.form.inttime).getTime() / 1000),
					endtime: this.form.endtime == "" ?
						"" : Math.floor(new Date(this.form.endtime).getTime() / 1000),
				};
				// console.log('xxxxxxxxxxxx',this.form)
				const externalLinkWithParams =
					`https://dscc.suishilian.com/admin/exceldc?nickname=${this.form.nickname}&shanghuuserid=${this.form.shanghuuserid}&shanghuid=${this.form.shanghuid}&name=${this.form.name}&phone=${this.form.phone}&inttime=${param.inttime}&endtime=${param.endtime}&title=日志导出`;
				console.log(externalLinkWithParams)
				window.location.href = externalLinkWithParams;
			},
			dateChange(e) {
				this.form.inttime = e[0]
				this.form.endtime = e[1]
			},
			async getcouponlist1() {
				var params = this.form
				params.shanghuuserid = params.shanghuuserid == '' ? '' : parseInt(params.shanghuuserid)
				logListApi(params).then(res => {
					if (res.code == 0) {
						this.tableData = res.data.data;
						this.total = res.data.totalCount;
						// if (result.data.data != null) {
						//   result.data.data.forEach((item) => {
						//     if (item.status == 1) {
						//       this.$set(item, "switch", true);
						//     } else {
						//       this.$set(item, "switch", false);
						//     }
						//   });
						// }
					}
				})
			},
			getSimpleText(html) {
				var re1 = new RegExp("<.+?>", "g"); //匹配html标签的正则表达式，"g"是搜索匹配多个符合的内容
				var msg = html.replace(re1, ""); //执行替换成空字符
				return msg;
			},
			searchclick() {
				this.getcouponlist1();
			},

			daochu() {
				console.log('---')
				let param = {
					inttime: this.form.inttime == "" ?
						"" : Math.floor(new Date(this.form.inttime).getTime() / 1000),
					endtime: this.form.endtime == "" ?
						"" : Math.floor(new Date(this.form.endtime).getTime() / 1000),
					title: this.form.title,
				};
				// this.$router.push({ path: "https://api.suishilian.com/admin/exceldc", query: param });
				const externalLinkWithParams =
					`https://api.suishilian.com/admin/exceldc?inttime=${param.inttime}&endtime=${param.endtime}&title=${param.title}`;

				window.location.href = externalLinkWithParams;
			},

			resetSearch() {
				this.form = {
					pageNo: 1,
					pageSize: 15,
					shanghuuserid: '',
					shanghuid: '',
					nickname: '',
					name: '',
					phone: '',
					inttime: '',
					endtime: '',
				}
				this.getcouponlist1();
			},
			addrenyuan() {
				this.$refs.add.add();
			},
			// 子传父:自定义事件
			refresh() {
				this.getcouponlist1();
			},

			changelimit(val) {
				this.form.pageSize = val;
				this.getcouponlist1();
			},
			changecurrentPage(val) {
				this.form.pageNo = val;
				this.getcouponlist1();
			},
			changerenyuan(val) {
				this.$refs.add.edit(val);
			},
		},
		mounted() {
			this.getcouponlist1();
		},
		// created() {
		//   this.$nextTick(() => {
		//     this.form.uid = Number(this.$route.query.uid);
		//     // 获取服务
		//     this.getservetypes1();
		//   });
		// },
	};
</script>

<style lang="scss" scoped>
	.dashboard {
		&-container {
			margin: 30px;
		}

		&-text {
			font-size: 30px;
			line-height: 46px;
		}
	}
</style>